package bTree.LeetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 子集2 {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path = new ArrayList<>();

    public List<List<Integer>> subsetsWithDup(int[] nums) {
        res.add(new ArrayList<>());
        Arrays.sort(nums);
        backtracking(nums,0);
        return res;
    }

    private void backtracking(int[] nums, int startindex) {
        if(startindex==nums.length){
            return;
        }
        for (int i=startindex;i<nums.length;i++){
            if(i>startindex&&nums[i]==nums[i-1]){
                continue;
            }
            path.add(nums[i]);
            res.add(new ArrayList<>(path));
            backtracking(nums,i+1);
            path.remove(path.size()-1);
        }
    }
}